package ModelLayer;

import java.lang.IllegalArgumentException;
/**
 * This class is part of an address book system. It's an aggregation of class AddressBook, and contains personal
 * data for anyone contained within the addressbook. 
 *
 * The purpose of this class is to supply information to the ControlLayer. 
 * 
 * @author Anders A.P, Anna K., Danny M.P., Jakob K., Mie P.  
 * @version 1.0
 */
public class Person 
{
    private String id,                              
                   name,                            
                   address,
                   postalCode,
                   city,
                   phone;

    /**
     * Constructs an instance of Person, taking the following parameters (throwing exceptions if
     * parameters contain bad data).
     *
     * @param id            Person id, in form of a String (has to be more than 1 character in length).
     * @param name          Person name, in form of a String (has to be more than 1 character in length).
     * @param address       Person address, in form of a String (has to be more than 1 character in length).
     * @param postalCode    Person postalCode, in form of a String (has to be more than 1 character in length).
     * @param city          Person city, in form of a String (has to be more than 1 character in length).
     * @param phone         Person phone, in form of a String (has to be more than 1 character in length).
     * @throw Exception     If any of the strings are blank or null.
     */
    public Person(String id,
                  String name,
                  String address,
                  String postalCode,
                  String city,
                  String phone) 
    {

        if (!setID(id)) {
            throw new IllegalArgumentException("id contains bad data.");
        }
        if (!setName(name)) {
            throw new IllegalArgumentException("name contains bad data.");
        }                   
        if (!setAddress(address, postalCode, city)) {
            throw new IllegalArgumentException("address contains bad data.");
        }
        if (!setPhone(phone)) {
            throw new IllegalArgumentException("phone contains bad data.");
        }

    }

    /**
     * Sets new information for id instance variable, taking the following parameters:
     *
     * @param   id        Person id, in form of a String (has to be more than 1 character in length).
     * @return  false    If id is shorter than 1 or null.
     * @return  true     If id is is changed succesfully.
     */
    public boolean setID(String id)
    {
        if (id.trim().length() > 0) {
            this.id = id;
            return true;
        }
        else {
            return false;
        }    
    }

    /**
     * Sets new information for name instance variable, taking the following parameters:
     *
     * @param   name      Person name, in form of a String (has to be more than 1 character in length).
     * @return  false    If name is shorter than 1 or null.
     * @return  true     If name is is changed succesfully .
     */
    public boolean setName(String name)
    {
        if (name.trim().length() > 0) {
            this.name = name;
            return true;
        }
        else {
            return false;
        }    
    }

    /**
     * Sets new information for address, postalCode and city instance variables, taking the following parameters:
     *
     * @param   address       Person address, in form of a String (has to be more than 1 character in length).
     * @param   postalCode    Person postalCode, in form of a String (has to be more than 1 character in length).
     * @param   city          Person city, in form of a String (has to be more than 1 character in length).
     * @return  false        If address is shorter than 1 or null.
     * @return  true         If false is changed succesfully.
     * @throw   Exception     If postalCode or city Strings are shorter than 1 or null.
     */
    public boolean setAddress(String address, String postalCode, String city)
    {

        if (!setPostalCode(postalCode)) {
            throw new IllegalArgumentException("postalCode did not pass testing.");
        }
        if (!setCity(city)) {
            throw new IllegalArgumentException("city did not pass testing.");
        }  
        if (address.trim().length() > 0) {
            this.address = address;
            return true;
        }
        else {
            return false;
        }
  
    }

    /**
     * Sets new information for postalCode instance variable, taking the following parameters:
     *
     * @param   postalCode  Person postalCode, in form of a String (has to be more than 1 character in length).
     * @return  false       If postalCode is shorter than 1 or null.
     * @return  true        If postalCode is is changed succesfully. 
     */
    private boolean setPostalCode(String postalCode)
    {
        if (postalCode.trim().length() > 0) {
            this.postalCode = postalCode;
            return true;
        }
        else {
            return false;
        }    
    }

    /**
     * Sets new information for city instance variable, taking the following parameters:
     *
     * @param   city    Person city, in form of a String (has to be more than 1 character in length).
     * @return  false   If city is shorter than 1 or null.
     * @return  true    If city is is changed succesfully.
     */
    private boolean setCity(String city)
    {
        if (city.trim().length() > 0) {
            this.city = city;
            return true;
        }
        else {
            return false;
        }    
    }

    /**
     * Sets new information for phone instance variable, taking the following parameters:
     *
     * @param   phone   Person phone, in form of a String (has to be more than 1 character in length).
     * @return  false   If phone is shorter than 1 or null.
     * @return  true    If phone is is changed succesfully. 
     */
    public boolean setPhone(String phone)
    {
        if (phone.trim().length() > 0) {
            this.phone = phone;
            return true;
        }
        else {
            return false;
        }    
    }

    /**
     * Returns the id instance variable to the caller.
     *
     * @return  id  Returns the instance variable id.
     */
    public String getID() 
    {
        return this.id;
    }

    /**
     * Returns the name instance variable to the caller.
     *
     * @return  name    Returns the instance variable name.
     */
    public String getName()
    {
        return this.name;
    }

    /**
     * Returns the address instance variable to the caller.
     *
     * @return  address Returns the instance variable address.
     */
    public String getAddress()
    {
        return this.address;
    }

    /**
     * Returns the postalCode instance variable to the caller.
     *
     * @return  postalCode  Returns the instance variable postalCode.
     */
    public String getPostalCode() 
    {
        return this.postalCode;
    }

    /**
     * Returns the id instance variable to the caller.
     *
     * @return  city    Returns the instance variable city.
     */
    public String getCity() 
    {   
        return this.city;
    }

    /**
     * Returns the phone instance variable to the caller.
     *
     * @return  phone   Returns the instance variable phone.
     */
    public String getPhone()
    {
        return this.phone;
    }
}